package com.xm.event;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestEvent {
    public static void main(String[] args) {
        EventManager manager = new EventManager();

        //注册监听器
        MyEventListener listener1 = new ConcreEventListener();
        MyEventListener listener2 = new ConcreEventListener();

        manager.addListener(listener1);
        manager.addListener(listener2);

        log.info("发布事件");
        manager.dispatchEvent(new MyEvent(manager, "First Event"));

        log.info("移出其中一个监听器");
        manager.removeListener(listener1);

        log.info("再次发布事件");
        manager.dispatchEvent(new MyEvent(manager, "Second Event"));

        log.info("添加一个监听器");
        MyEventListener listener3 = new ConcreEventListener();
        manager.addListener(listener3);

        log.info("再次发布事件");
        manager.dispatchEvent(new MyEvent(manager, "Third Event"));
    }
}
